﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;

namespace S2_SmartCode
{
    public class Repositories
    {
        public static void Create(string strModelNameSpace, string strBllNameSpace, string strDalNameSpace, string strModel)
        {
            string str = strModel;
            StreamWriter writer = File.CreateText("BLL/" + str + ".cs");
            writer.WriteLine("using System;");
            writer.WriteLine("using System.Collections.Generic;");
            writer.WriteLine("using System.Data;");
            writer.WriteLine("using System.Data.Linq.Mapping;");
            writer.WriteLine("using System.Linq;");
            writer.WriteLine("using System.Runtime.Serialization;");
            writer.WriteLine("using System.Text;");
            writer.WriteLine("//");
            writer.WriteLine("using " + strModelNameSpace + ".Common;");
            writer.WriteLine("using " + strModelNameSpace + ";");
            writer.WriteLine("using " + strDalNameSpace + ";");

            writer.WriteLine(" ");
            writer.WriteLine("namespace " + strBllNameSpace);
            writer.WriteLine("{");
            writer.WriteLine("    /// <summary>");
            writer.WriteLine("    /// 此处填写类的描述");
            writer.WriteLine("    /// </summary>");
            writer.WriteLine("    public class " + str + " : BaseBLL<" + strModelNameSpace + "." + strModel + ">");
            writer.WriteLine("    {");
            writer.WriteLine("          private readonly " + strDalNameSpace + "." + strModel + " _dal = DALFactory<" + strDalNameSpace + "." + strModel + ">.Instance;");
            writer.WriteLine("          ");
            writer.WriteLine("          public " + strModel + "()");
            writer.WriteLine("          {");
            writer.WriteLine("              base.BaseDal = _dal;");
            writer.WriteLine("          }");
            writer.WriteLine("    }");
            writer.WriteLine("}");
            writer.Flush();
            writer.Close();
            StreamReader reader = new StreamReader("BLL/" + str + ".cs");
            reader.Close();
        }
    }
}
